$(function () {
    var form = new xhForm($('#xh_form'));
    form.parse();
    form.fill(info);
    if($('[name=iType]').val() == 2){
        $('[name="sProdIds[]"]').select2();
        if(info['sProdIds']){
            $('[name="sProdIds[]"]').val(info['sProdIds'].split(',')).trigger('change');
        }
    }

    $('#save').click(function () {
        window.top.swal({
            title:  '确认保存么？',
            showCancelButton: true,
            cancelButtonText: '取消',
            confirmButtonText: '确认',
            allowOutsideClick: true,
            showCloseButton: true,
            showLoaderOnConfirm: true,
            type: 'warning',
            preConfirm: function() {
                return new Promise(function (resolve, reject) {
                    form.submit('coop/saveInfo',{},function (res) {
                        window.top.xhTop.showSuccess(res.msg);
                        location.reload();
                    })
                })
            }
        }).then(function(isConfirm) {}, function(dismiss) {});
    });
});